<!doctype html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Ajax-01-Axios方式</title>
    <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
</head>
<style>
    * {
        margin: 0;
        padding: 0;
        box-sizing: border-box;
    }

    body {
        background-color: #222;
        color: snow;
    }
</style>
<body>
<script>
    // axios({
    //     method: 'GET',
    //     url: 'https://jsonplaceholder.typicode.com/posts',
    // }).then((response) => {
    //     console.log(response.data);
    // });
    axios.get('https://jsonplaceholder.typicode.com/posts').then((response) => {
        console.log(response.data);
    });

    // axios({
    //     method: 'POST',
    //     url: 'https://jsonplaceholder.typicode.com/posts',
    //     data: {
    //         userId: 1, title: 'Hello Axios!', body: 'this is a test',
    //     },
    // }).then((response) => {
    //     console.log(response.data);
    // });
    axios.post('https://jsonplaceholder.typicode.com/posts', {
        userId: 2, title: 'Hello Axios!', body: 'this is a test',
    }).then((response) => {
        console.log(response.data);
    });
</script>
</body>
</html>